
module HomeHelper

  def get_products_for_home category_id
    Product.where("? = ANY(parent_category_ids)", category_id.to_s).limit(4)
  end

  def get_wiki_video_address wiki
    doc = Nokogiri::HTML(wiki.content, nil, 'utf-8')
    doc.at('embed').attr('src') rescue "/demo.mp4"
  end

  def floor_icon(index)
    case index
    when 0
      '<span class="icon-home-1f-yangtai"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span><span class="path5"></span><span class="path6"></span><span class="path7"></span><span class="path8"></span><span class="path9"></span><span class="path10"></span></span>'
    when 1
      '<span class="icon-home-2f-yangtai"><span class="path1"></span><span class="path2"></span></span>'
    when 2
      '<span class="icon-home-3f-keting"><span class="path1"></span><span class="path2"></span></span>'
    when 3
      '<span class="icon-home-4f-chufang"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span><span class="path5"></span></span>'
    when 4
      '<span class="icon-home-5f-yangguangfang"><span class="path1"></span><span class="path2"></span></span>'
    end
  end

  def get_first_sub_cate category_id
    cate = Category.find(category_id)
    if cate.is_childless?
      category_id
    else
      cate.children.first.try(:id)
    end
  end

end
